#config.pm
#Command line processing library
#Method list:
# new(\@ARGV);		constructor, takes the pointer to the command line option array
# setObj(\@ARGV);	a method to initialize the class data (PRIVATE)
# optionarg($ARGV);	takes an argument/option name and returns the corresponding value (PUBLIC)
# optionflag($ARGV);	takes an argument/option name and returns true if the option exists and false else (PUBLIC)

#Version: 1.0
#@autor: Igor Jauk

package config;

sub new {
	my $object = shift;
	my $AR = shift;
	my $ref = {};
	bless($ref, $object);
	$ref->setObj($AR);
	#foreach $b (@{$object->{ar}}) {
	#	print $b."\n";
	#}
	return($ref);
}

sub setObj {
	my ($object, $AR) = @_;
	$object->{ar} = $AR;
}

sub optionarg {
	my ($object, $argv) = @_;
	for (my $i = 0; $i < @{$object->{ar}}; $i++) {
		if ($argv eq $object->{ar}->[$i] && index($object->{ar}->[$i+1],"-") != 0) {
			return($object->{ar}->[$i+1]);
		}
	}
	return(defined);
}

#checks the existence of a command line option
sub optionflag {
	my ($object, $argv) = @_;
	foreach $o (@{$object->{ar}}) {
		if ($argv eq $o) {
			return(1);
		}
	}
	return(0);
}

1;
